package com.example.jdshopdetailtwo;

import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.widget.Toolbar;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.jdshopdetailtwo.adapter.ViewPagerAdapter;
import com.example.jdshopdetailtwo.base.BaseActivity;
import com.example.jdshopdetailtwo.fragment.FMBodyDetail;
import com.example.jdshopdetailtwo.fragment.FMCommodity;
import com.example.jdshopdetailtwo.fragment.FMCommonList;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author: njb
 * @date: 2020/5/20 0020 23:11
 * @desc:主界面
 */
public class MainActivity extends BaseActivity {
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.shop_tabLayout)
    TabLayout shopTabLayout;
    @BindView(R.id.iv_share)
    ImageView ivShare;
    @BindView(R.id.iv_title_right)
    ImageView ivTitleRight;
    @BindView(R.id.ll_head)
    ConstraintLayout llHead;
    @BindView(R.id.toolbar_title1)
    TextView toolbarTitle1;
    @BindView(R.id.toolbar1)
    Toolbar toolbar1;
    @BindView(R.id.ll_shop_title)
    ConstraintLayout llShopTitle;
    @BindView(R.id.content_cl)
    ConstraintLayout contentCl;
    private FMCommodity fmCommodity = new FMCommodity();
    private FMCommonList fmCommonList = new FMCommonList();
    private FMBodyDetail fmBodyDetail = new FMBodyDetail();
    private List<Fragment> list;
    private ViewPagerAdapter vpAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        initTabLayout();
    }

    private void initTabLayout() {
        list = new ArrayList<>();
        list.add(fmCommodity);//商品
        list.add(fmCommonList);//评价
        list.add(fmBodyDetail);//详情
        vpAdapter = new ViewPagerAdapter(getSupportFragmentManager(), list);
        viewPager.setAdapter(vpAdapter);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener
                (shopTabLayout));
        shopTabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener
                (viewPager));
        fmCommodity.setHead(llHead, shopTabLayout, viewPager);
    }

    @Override
    protected void addListener() {

    }
}